package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerNewTClickListener;
import com.lemon.smartsafetynew.entity.common.DateTypeEnum;
import com.lemon.smartsafetynew.entity.record.CompanyPeopleVo;
import com.lemon.smartsafetynew.util.common.CommonUtil;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by JiangAn on 2018/5/23.
 */

public class CompanyPeopleAdapter extends LemonRcvAdapter<CompanyPeopleVo> {
    private int[] ids = new int[]{R.drawable.head_dark_blue,R.drawable.head_light_red, R.drawable.head_dark_green, R.drawable.head_dark_yellow,R.drawable.head_light_blue,R.drawable.head_light_green1, R.drawable.head_dark_red,};
    private RecyclerNewTClickListener<CompanyPeopleVo> mListener;
    private boolean isShowLiscence=false;
    //启用 #8BD9A6  禁用 #E58E7F
    public CompanyPeopleAdapter(@Nullable List<CompanyPeopleVo> data, RecyclerNewTClickListener<CompanyPeopleVo> mListener,boolean isShowLiscence) {
        super(data);
        this.mListener = mListener;
        this.isShowLiscence = isShowLiscence;
    }


    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new CompanyPeopleAdapter.Item();
    }

    public class Item implements AdapterItem<CompanyPeopleVo> {
        @Bind(R.id.tv_company_people_name)
        TextView tvCompanyPeopleName;
        @Bind(R.id.tv_company_people_duty)
        TextView tvCompanyPeopleDuty;
        @Bind(R.id.tv_company_telephone_number)
        TextView tvCompanyTelephoneNumber;
        @Bind(R.id.tv_head_people)
        TextView tvHeadPeople;
        CompanyPeopleVo data;
        @Bind(R.id.tv_licence_name)
        TextView tvLicenceName;
        @Bind(R.id.tv_licence_date)
        TextView tvLicenceDate;
        @Bind(R.id.ll_liscence)
        LinearLayout llLiscence;
        private int pos;

        @Override
        public int getLayoutResId() {
            return R.layout.layout_company_people_item;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            tvCompanyTelephoneNumber.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mListener.onNewItemClick(data, pos);
                }
            });
        }

        @Override
        public void handleData(CompanyPeopleVo companyPeopleVo, int position) {

            data = companyPeopleVo;
            pos = position;

            tvCompanyPeopleName.setText(companyPeopleVo.getUser_name());
            tvHeadPeople.setText(companyPeopleVo.getUser_name().substring(0, 1));
            tvHeadPeople.setBackgroundResource(ids[position % 7]);
            tvCompanyPeopleDuty.setText(companyPeopleVo.getType_name());
            tvCompanyTelephoneNumber.setText(companyPeopleVo.getMobile());
            if(isShowLiscence) {
                if (TextUtils.isEmpty(companyPeopleVo.getSafety_name())) {
                    llLiscence.setVisibility(View.GONE);
                } else {
                    llLiscence.setVisibility(View.VISIBLE);
                    tvLicenceName.setText(companyPeopleVo.getSafety_name());
                    tvLicenceDate.setText("有效期至:" + CommonUtil.secondToTimeStr(companyPeopleVo.getCertificate_end_time(), DateTypeEnum.DAY));
                }
            }else{
                llLiscence.setVisibility(View.GONE);
            }
        }
    }
}

